#include <bits/stdc++.h>
#define int long long
#define inf 100000000000000004ll
using namespace std;
int n,ans,l[100010],r[100010];
struct node{
	int alp,bet;
}a[100005];
bool cmp(const node &xxx,const node &yyy){
	if(xxx.bet!=yyy.bet) return xxx.bet<yyy.bet;
	return xxx.alp<yyy.alp;
}
signed main(){
	freopen("boast.in","r",stdin);
	freopen("boast.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&a[i].alp,&a[i].bet);
	sort(a+1,a+n+1,cmp);l[0]=r[n+1]=ans=inf;
	for(int i=1;i<=n;i++) l[i]=min(l[i-1],a[i].alp);
	for(int i=n;i>=1;i--) r[i]=min(r[i+1],a[i].bet+a[i].alp);
	for(int i=2;i<n;i++) ans=min(ans,a[i].alp+a[i].bet+l[i-1]+r[i+1]);
	cout<<ans;
	return 0;
}
